# 基础镜像
FROM registry.cn-hangzhou.aliyuncs.com/dwyanewang/bookworm-node-bun:slim-20.15.0-1.1.17 as base
WORKDIR /root/rms

COPY package.json ./
COPY .env ./

# 安装依赖
FROM base as install

COPY bun.lockb ./

RUN bun install

# 安装依赖、项目打包
FROM base as builder

COPY --from=install /root/rms/node_modules  ./node_modules
COPY src ./src

RUN bun run build

# 构建制品镜像
FROM registry.cn-hangzhou.aliyuncs.com/dwyanewang/alpine:3.20
WORKDIR /root/rms

COPY --from=builder /root/rms/package.json ./
COPY --from=builder /root/rms/.env ./
COPY --from=builder /root/rms/server  ./

VOLUME ["/root/rms/logs"]
VOLUME ["/root/rms/static"]

EXPOSE 8890

CMD bun run start